<?php
require_once("registereduserobj.php");
include("menu.php");
$user = authenticate(1);
//authorise("userinput");
(isset($_REQUEST["restart"])) ? $restart = $_REQUEST["restart"] : $restart = "NULL" ;
(isset($_REQUEST["sub"])) ? $sub = $_REQUEST["sub"] : $sub = "NULL" ;
$obj = new registereduser();
$obj->applyfromuser();
$obj->applyfromrequest();
if ($sub=="Save" && $obj->valid) {
 $ans = $obj->writedb();
  if ($ans=="1") {
   confirmfiled();
   $obj->unload();
  } else {
    echo "failed badly";
    echo $ans;
    showpage($obj);
  }
} else {
 if (strlen($obj->header[0]) > 0) {
	showpage($obj);
 } else {
  print "<pre>";
  print_r($obj);
  echo "An error has occurred. Please refresh your browser";
  unset($_SESSION["REGISTEREDUSER"]);
 }
}
 
function confirmfiled() {
 echo "Changes made as requested";
}

function showpage($obj) {

 $i = $obj->header;
 
 echo "<h1>User Setup</h1>";
 echo "<form name='form' method=post>";
 echo "<table>";
 
 echo "<tr>";
 echo "<td>Email</td>";
 echo "<td>";
 echo "<input name=f0 value='$i[9]'>";
 echo "</td>";
 echo "<td>";
 echo $obj->valids[9];
 echo "</td>";
 echo "</tr>";

 echo "<td>Name</td>";
 echo "<td>";
 echo '<input name=f1 value="'.$i[1].'">';
 echo "</td>";
 echo "<td>";
 echo $obj->valids[1];
 echo "</td>";
 echo "</tr>";

 echo "<tr>";
 echo "<td>New Password</td>";
 echo "<td>";
 echo "<input type=password name=f5>";
 echo "</td>";
 echo "</tr>";

 echo "<tr>";
 echo "<td>New Password (again)</td>";
 echo "<td>";
 echo "<input type=password name=i5>";
 echo "</td>";
 echo "<td>";
 echo $obj->valids[5];
 echo "</td>";
 echo "</tr>";


 echo "</tr>";
 echo "</table>";
 echo "<input type=submit name=sub value=Save>";
 echo "</form>"; 
 }
?>